<?php

class Common_model extends CI_Model{
	
	public function __construct(){
		parent::__construct();
	}
	
	function select($zone_id){
        return $this->db_front->get_where('zone', array('zone_id'=>$zone_id))->row();
    }
	
	function getTotalCustomer(){
		return $this->db_front->query('select count(customer_id) as customer from customer')->row();
	}
	
	function getTotalCustomerByYear($year){
		return $this->db_front->query('select count(customer_id) as total_customer_year from `customer` where YEAR(date_add) = "'.$year.'"')->row();	
	}
	
	function getTotalSales(){
		return $this->db_front->query('select sum(total) as total_sales from `order`')->row();	
	}
	
	function getTotalSalesByYear($year){
		return $this->db_front->query('select sum(`total`) as total_sales_year from `order` where YEAR(date_added) = "'.$year.'"')->row();	
	}
	
	function getTotalSalesPaid(){
		return $this->db_front->query('select sum(total) as total_sales from `order` where payment_status_id = 2')->row();	
	}
	
	function getTotalSalesPaidByYear($year){
		return $this->db_front->query('select sum(`total`) as total_sales_year from `order` where YEAR(date_added) = "'.$year.'" and payment_status_id = 2')->row();	
	}
	
	function getAll(){
		
		
		$this->db_front->limit(10);
		$this->db_front->order_by('date_added','desc');
		$query = $this->db_front->get('order');
		//echo $this->db->last_query();
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
	function get_order_status(){
		$query = $this->db_front->get('order_status');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
}

?>